<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.jsdelivr.net/npm/vue@2"></script>
</head>

<body>
    <div id="app">
        <p class="one">拾忆记事本</p>
        <p class="two">记录生活点点滴滴，卸下生活每一个美好</p>
        <div class="head">
            <button class="btn1">内容</button>
            <input type="text" class="ipt" v-model="word">
            <button class="btn" @click="add">确认</button>
        </div>
        <ol class="ol">
            <li v-for="(item,key) in list" :key="key">
                <p>{{key+1}}、</p>
                <p>{{item.title}}</p>
                <span class="del" @click="del(key)">X</span>
            </li>
        </ol>
        <div v-show="num==0" class="a">暂无数据</div>
        <div class="foot">
            <span>总数{{num}}</span>
            <span @click="clear">清除</span>
        </div>

    </div>
</body>

</html>

<script>
    new Vue({
        el: '#app',
        data: {
            word: '',
            list: JSON.parse(localStorage.getItem('list')) || []
        },
        methods: {
            add() {
                let obj = { title: this.word, flag: false, edit: false }
                this.list.push(obj)
                localStorage.setItem('list', JSON.stringify(this.list))
                this.word = ''
            },
            del(key) {
                if (confirm('确定要删除吗？')) {
                    this.list.splice(key, 1)
                }

                localStorage.setItem('list', JSON.stringify(this.list))
            },
            clear() {
                this.list = []
                localStorage.setItem('list', JSON.stringify(this.list))
            }
        },
        computed: {
            num() {
                return this.list.length
            }
        }
    })
</script>

<style>
    * {
        margin: 0;
        padding: 0;
    }
    .two{
        width: 1000px;
        margin: auto;
    }
    .one {
        font-size: 30px;
        width: 1000px;
        margin: auto;
    }

    .head {
        width: 1000px;
        height: 40px;
        margin: auto;
        margin-top: 20px;
        border: 3px solid gray;
        display: flex;
        justify-content: space-between;
        margin-bottom: 50px;
    }

    .btn {
        width: 100px;
        height: 99%;
        border: none;
    }

    .btn1 {
        width: 100px;
        height: 99%;
        border: none;
    }

    .ipt {
        flex: 1;
        height: 100%;
        border: none;
        outline: none;
        font-size: 20px;
    }

    ol {
        width: 1000px;
        margin: auto;
    }

    li {
        width: 100%;
        height: 40px;
        margin-top: 10px;
        line-height: 40px;
        font-size: 20px;
        display: flex;
        justify-content: space-between;
        border: 1px solid gray;
    }

    .del {
        font-size: 30px;
    }

    .foot {
        width: 1000px;
        margin: auto;
        font-size: 30px;
        display: flex;
        justify-content: space-between;
    }
    .a{
        width: 1000px;
        margin: auto;
        text-align: center;
    }
</style>